<?php
namespace  My\Controller;
use Utuo\BackgroundController;
use Utuo\Form;

class BrotherHelpController extends BackgroundController
{
	public function _initialize() {
		$this->setControllerTitle("师兄帮忙管理");
		$this->setActionTitle(array(
				'index' => '师兄帮忙列表',
				'show' => '师兄帮忙详情',
				'recycle' => '回收站'
		));
		$this->setActionNav(array(
				'index',
				'recycle'
		));
		$this->setLinkNav("全部", U("BrotherHelp/index"));
		foreach (D("BrotherHelp")->status as $k => $v) {
			$this->setLinkNav($v, U("BrotherHelp/index?status=".$k));
		}
	}
	public function indexAction($status=null){
		$this->getLists(0,$status);
	}
	public function recycleAction($status=null){
		$this->getLists(1,$status);
	}
	public function getLists($is_delectd,$status=null){
		$condation=array(
		     'sid'=>$this->aid,
			'is_deleted'=>$is_delectd	
		);
		$status!==null and $condation['status']=$status;
		$brotherHelp=D('BrotherHelp')->where($condation)->page($this->getPage(),$this->getPageSize())->select();
		foreach ($brotherHelp as &$v){
			$v['statusOptions'] = Form::getOption(D("BrotherHelp")->status, $v['status']);
		}
		$count=D('BrotherHelp')->where($condation)->count();
		$this->showPage($count, $this->getPageSize());
		$this->assign('brotherHelp',$brotherHelp)->display();
	}
	public  function showAction($id){
		$brotherHelp=D('BrotherHelp')->find($id);
		$this->assign("brotherHelp",$brotherHelp)->display();
	}
	
	 // 设置审核状态
	public function setStatusAction() {
		$id = I("id", 0, "intval");
		$status = I("status", 0, "intval");
		$d = M("BrotherHelp");
		if (false!==$d->where("id={$id}")->setField("status", $status)) {
			$this->ajaxSuccess();
		} else {
			$this->ajaxError($d->getError());
		}
	} 
}